package com.aier.common.common;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import javax.annotation.Resource;

import org.springframework.beans.factory.InitializingBean;

import com.aier.entrance.icsocket.EntranceSendCommand;
import com.aier.entrance.service.IEntranceCardService;

public class EntranceStart implements InitializingBean {

    @Resource(name="entranceCardService")
    private IEntranceCardService entranceCardService;
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("设备监听器启动");
        try {
            ServerSocket ss = new ServerSocket(Constant.num_8000);
            Socket s;
            while(true){
                s = ss.accept();
                EntranceSendCommand send = new EntranceSendCommand(s, null, null, Constant.num_8000, entranceCardService);
                //开辟一个线程来读取
                send.new receiveMsgFromDev(s);
                //receiveMsgFromDev rmfd = send.new receiveMsgFromDev(s);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    

    }
    public void setEntranceCardService(IEntranceCardService entranceCardService) {
        this.entranceCardService = entranceCardService;
    }

}
